import time

import akshare as ak
import pandas as pd

# 升级akshare
# pip install akshare --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple

# A股股票指数数据 - 实时行情数据 - 东财
# "上证系列指数", "深证系列指数", "指数成份", "中证系列指数"
df1 = ak.stock_zh_index_spot_em(symbol="上证系列指数")
df2 = ak.stock_zh_index_spot_em(symbol="深证系列指数")
df3 = ak.stock_zh_index_spot_em(symbol="指数成份")
df4 = ak.stock_zh_index_spot_em(symbol="中证系列指数")

df = pd.concat([df1, df2, df3, df4])
df = df.drop_duplicates(subset=["代码", "名称"])
date = time.strftime("%Y%m%d", time.localtime())
df = df.sort_values(by="代码")    # 按代码进行升序排列
df.to_excel(f"A股指数-东财-{date}.xlsx", index=False)

